package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.RightsMapper;
import com.jt.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 创建时间：2021/8/6 0:38
 * @author： Colin
 */
@Service
public class RightsServiceImpl implements RightsService {
    @Autowired
    private RightsMapper rightsMapper;
    @Override
    public List<Rights> getRightsList() {
        QueryWrapper<Rights> queryWrapper = new QueryWrapper<Rights>();
        queryWrapper.eq("parent_id",0);
        List<Rights> oneList = rightsMapper.selectList(queryWrapper);
        for(Rights oneRight:oneList){
            queryWrapper.clear();
            queryWrapper.eq("parent_id",oneRight.getId());
            List<Rights> twoList = rightsMapper.selectList(queryWrapper);
            oneRight.setChildren(twoList);
        }
        return oneList;
    }
}
